# -*- coding: utf-8 -*-
# -文件说明  百度搜索关键词提交：http://www.baidu.com/s?wd=-
# @Time    : 2019/8/8 16:30
# @Author  : hwx
# @Email   : @163.com
# @File    : 爬虫demo2_百度搜索.py
# @Software: PyCharm
import requests


def getHTMLText3(url, pas):
    try:
        r = requests.get(url, pas)  # 请用get，用post出错
        print('状态码：' + str(r.status_code))
        print(r.request.url)
        r.raise_for_status()  # 如果不是200，抛出异常
        r.encoding = 'utf-8'
        return r.text
    except BaseException:
        return "getHTMLText产生异常"


# http://www.baidu.com/s  https://item.jd.com/100003395445.html
url = "http://www.baidu.com/s"
# https://www.amazon.cn/dp/B07G1Z4KFR
params = {'wd': '中国慕课'}
print(getHTMLText3(url, params)[100:1000])
